<?php
class Silk_Mapi_CmsController extends Silk_Mapi_Controller_Action {
    public function pageAction()
    {
        $id = $this->getRequest()->getParam('id');
        $callback = $this->getRequest()->getParam('callback');
        $helper = Mage::helper('cms');
        $html = "";
        if(!$id)
        {
            $html = "访问出错！";
        }
        else
        {
            $cms = Mage::getModel('cms/page')->load($id,'identifier');
            $processor = $helper->getPageTemplateProcessor();
            $html = $processor->filter($cms->getContent());
        }
        $json = json_encode(array('html'=>$html,'title'=>$cms->getTitle()));



        if($callback)
        {
            $data = "{$callback}({$json})";
        }
        else
        {
            $data = $json;
        }

        $response = $this->getResponse();
        $response->setHeader('Content-type', 'application/json');
        $response->setBody($data);
    }
}